package admin

import (
	"github.com/gin-gonic/gin"

	"server/internal/app/api/admin/controller"
	"server/internal/app/api/admin/middleware"
)

func Register(engine *gin.Engine) {
	// 基础路由
	router := engine.Group("/admin/api")

	// 账号路由
	accountRouter := router.Group("/account")
	{
		accountController := controller.NewAccountController()
		accountRouter.POST("/register", accountController.Register)
		accountRouter.POST("/login", accountController.Login)
		accountRouter.POST("/logout", accountController.Logout)
		accountRouter.Use(middleware.Auth()).GET("/profile", accountController.Profile)
	}

	//需要登录和权限
	router.Use(middleware.Auth(), middleware.Permission())

	//RBAC 权限管理
	rbacCtl := controller.NewRbacController()
	rbacRouter := router.Group("/rbac")
	{
		rbacRouter.GET("/role/list", rbacCtl.GetRoleList)
		rbacRouter.POST("/role/create", rbacCtl.CreateRole)
		rbacRouter.POST("/role/update", rbacCtl.UpdateRole)
		rbacRouter.POST("/role/delete", rbacCtl.DeleteRole)
		rbacRouter.GET("/permission/list", rbacCtl.GetPermissionList)
		rbacRouter.POST("/permission/create", rbacCtl.CreatePermission)
		rbacRouter.POST("/permission/update", rbacCtl.UpdatePermission)
		rbacRouter.POST("/permission/delete", rbacCtl.DeletePermission)
		rbacRouter.POST("/role/permission/assign", rbacCtl.AssignRolePermission)
		rbacRouter.POST("/admin/role/assign", rbacCtl.AssignAdminRole)
	}
}
